﻿using System.Collections.Generic;
using System.Xml.Serialization;

namespace SS.Net.AppGen.Models
{
    /// <summary>
    /// The class is corresponding with the element ClassComponents in xml file
    /// </summary>
    public class ClassComponents
    {
        #region Fields

        private readonly char[] TrimChars = new char[] { '\r', '\n' };
        private string usingPart;

        #endregion

        #region Properties

        /// <summary>
        /// Content of using region
        /// </summary>
        [XmlElement("UsingPart")]
        public string UsingPart 
        {
            get
            {
                return this.usingPart.TrimEnd().TrimStart(this.TrimChars);
            }
            set
            {
                this.usingPart = value;
            }
        }

        /// <summary>
        /// Content of class region
        /// </summary>
        [XmlElement("ClassPart")]
        public ClassPart ClassPart { get; set; }

        #endregion
    }

    /// <summary>
    /// ClassPart > ClassPart
    /// </summary>
    public class ClassPart
    {
        #region Fields

        private readonly char[] TrimChars = new char[] { '\r', '\n' };
        private string comment;

        #endregion

        #region Properties

        /// <summary>
        /// Content of comment
        /// </summary>
        [XmlElement("Comment")]
        public string Comment
        {
            get
            {
                return this.comment.TrimEnd().TrimStart(this.TrimChars);
            }
            set
            {
                this.comment = value;
            }
        }

        /// <summary>
        /// Array of regions content
        /// </summary>
        [XmlArray("Regions")]
        [XmlArrayItem("Region")]
        public List<Region> Regions { get; set; }

        #endregion
    }

    /// <summary>
    /// ClassPart > ClassPart > Regions[Region]
    /// </summary>
    public class Region
    {
        #region Fields

        private readonly char[] TrimChars = new char[] { '\r', '\n' };
        private string regionName;

        #endregion

        #region Properties

        /// <summary>
        /// Region name
        /// </summary>
        [XmlAttribute("RegionName")]
        public string RegionName
        {
            get
            {
                return this.regionName.TrimEnd().TrimStart(this.TrimChars);
            }
            set
            {
                this.regionName = value;
            }
        }

        /// <summary>
        /// Array of items in regions
        /// </summary>
        [XmlElement("Item")]
        public List<Item> Items { get; set; }

        #endregion
    }

    /// <summary>
    /// ClassPart > ClassPart > Regions[Region] > Items[Item]
    /// </summary>
    public class Item
    {
        #region Fields

        private readonly char[] TrimChars = new char[] { '\r', '\n' };
        private string content;

        #endregion

        #region Properties

        /// <summary>
        /// Mark item is foreign key pattern
        /// </summary>
        [XmlAttribute("IsFKPattern")]
        public string IsFKPattern { get; set; }

        /// <summary>
        /// Mark action type
        /// </summary>
        [XmlAttribute("ActionType")]
        public string ActionType { get; set; }

        /// <summary>
        /// The content of an item
        /// </summary>
        [XmlText]
        public string Content
        {
            get
            {
                return this.content.TrimEnd().TrimStart(this.TrimChars);
            }
            set
            {
                this.content = value;
            }
        }

        #endregion
    }
}
